<script type="text/javascript" src="{{= g_baseUrl}}common/js/md5-min.js"></script>
<script type="text/javascript" src="{{= g_baseUrl}}main/assets/js/plugins/notifications/sweet_alert.min.js"></script>
<!-- Page header -->
<div class="page-header page-header-default">
    <div class="page-header-content">
        <div class="page-title">
            <h4><i class="icon-arrow-left52 position-left"></i> <span class="text-semibold">个人信息</span> - 修改密码</h4>
        </div>
    </div>

    <div class="breadcrumb-line">
        <ul class="breadcrumb">
            <li><a><i class="icon-home2 position-left"></i> 个人信息</a></li>
            <li class="active">修改密码</li>
        </ul>
    </div>
</div>
<!-- /page header -->

<!-- Content area -->
<div class="content">
    <!-- Basic responsive configuration -->

    <form id="reset-passwd">
        <div class="panel panel-flat">
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-10 col-md-offset-1">

                        <div class="form-group">
                            <label>旧密码:</label>
                            <input type="password" class="form-control" placeholder="请输入原始密码" name="old-passwd">
                        </div>

                        <div class="form-group">
                            <label>新密码:</label>
                            <input type="password" class="form-control" placeholder="请输入新密码" name="new-passwd">
                        </div>

                        <div class="form-group">
                            <label>确认密码:</label>
                            <input type="password" class="form-control" placeholder="请确认新密码" name="new-passwd2">
                        </div>

                        <div class="text-right">
                            <button type="button" class="btn btn-primary" onclick="submitPasswd()"><i class="icon-checkmark3 position-left"></i>保存</button>
                            <button type="button" class="btn btn-default" onclick="cancel()"><i class="icon-undo position-left"></i>取消</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!-- /basic responsive configuration -->
    <!-- Footer -->
    <div id="page-content-footer"></div>
    <!-- /footer -->
</div>
<!-- /content area -->

<script>
    /* 提交表单 */
    var submitPasswd = function () {
        var request       = {};
        request.oldPasswd = $('#reset-passwd input[name ="old-passwd"]').val();
        request.newPasswd = $('#reset-passwd input[name ="new-passwd"]').val();
        if (!request.oldPasswd || !request.newPasswd) {
            Notific("密码不能为空");
            return;
        }
        request.oldPasswd = hex_md5(request.oldPasswd);
        request.newPasswd = hex_md5(request.newPasswd);

        AlpacaAjax({
            url: g_url + API['admin_auth_pwd'],
            data: request,
            async: false,
            success: function (data) {
                if (data.code == 9900) {
                    swal({
                        title: "修改成功",
                        text: "密码已经修改",
                        confirmButtonColor: "#66BB6A",
                        type: "success",
                        confirmButtonText: "确认",
                    }, function () {
                        Alpaca.to("#/main/auth/myInfoView");
                    });
                } else {
                    Notific(data.msg);
                }
            },
        });
    };

    /* 取消 */
    var cancel = function () {
        history.go(-1);
    }

</script>